/**
 * @author jstone
 */

var MainView = new KONtx.Class({
 	ClassName: 'MyCustomMainView',
	
	Extends: KONtx.system.SidebarView,

  teamData: {
    blast: "",
  },

  initView: function() {
    this._profileConnection();
  },

  _profileConnection: function() {
    KONtx.speedtest.profileConnection(
      function(speed) {
        KONtx.messages.store("bandwidthBitrate", speed); 
      });
  },

	createView: function() {
    this.controls.bgImage = new KONtx.element.Image({
      src: "image/960x540/main2.png",
      styles: {
        hOffset: KONtx.utility.scale(0),
        vOffset: KONtx.utility.scale(0),
      }
    }).appendTo(this);

    /*
    this.controls.bgFootballImage = new KONtx.element.Image({
      src: "image/960x540/football2.png",
      styles: {
        hOffset: KONtx.utility.scale(18),
        vOffset: KONtx.utility.scale(100),
      }
    }).appendTo(this);
    */

    //Team Icon:
    this.controls.teamIcon = new KONtx.element.Image({
      src: "image/960x540/team_icon.png",
      styles: {
        hOffset: KONtx.utility.scale(8),
        vOffset: KONtx.utility.scale(8),
      }
    }).appendTo(this);

    this.controls.teamName = new KONtx.element.Text({
      label: "hans_sucks", 
      truncation: 'end',
      styles: {
        fontSize: '24px',
        color: 'purple',
        fontWeight: 'bold',
        textAlign: 'left',
        hOffset: KONtx.utility.scale(120),
        vOffset: KONtx.utility.scale(6),
      }
    }).appendTo(this);
    
    this.controls.teamDetail = new KONtx.element.Text({
      label: "l-3-0 | Manager: " + "mx232", 
      truncation: 'end',
      styles: {
        fontSize: '14px',
        color: 'white',
        textAlign: 'left',
        hOffset: KONtx.utility.scale(120),
        vOffset: KONtx.utility.scale(36),
      }
    }).appendTo(this);
     
    this.controls.teamBlastContainer = new KONtx.element.Container({
      styles: {
        width: KONtx.utility.scale(this.width - 20),
        height: KONtx.utility.scale(60),
				hOffset: KONtx.utility.scale(10),
				//vOffset: KONtx.utility.scale(260),
				vOffset: this.height - KONtx.utility.scale(35 * 4 + 50 + 20),
        backgroundColor: '#FFFFCC',
      }
    }).appendTo(this);
    
    this.controls.teamBlast = new KONtx.element.Text({
      label: "My team totaly rocks! Go Go Go!, test test test test wrap", 
      wrap: true,
      truncation: 'end',
      styles: {
        width: KONtx.utility.scale(272),
        height: KONtx.utility.scale(60),
        vOffset: 8,
        fontSize: '16px',
        color: 'black',
        textAlign: 'center',
      }
    }).appendTo(this.controls.teamBlastContainer);
  
    this.controls.myTeamBtn = new KONtx.control.TextButton({
      label: "My Team",
			guid: "my-team",
      styles: {
				//vOffset: 380,
				height: KONtx.utility.scale(35),
				vOffset: this.height - KONtx.utility.scale(35 * 4)
      },
      events: {
        onSelect: function(event) {
					KONtx.application.loadView('team-View');
        }
      }
    }).appendTo(this);
  	
    this.controls.leagueBtn = new KONtx.control.TextButton({
      label: "League",
			guid: "league",
			styles: {
				height: KONtx.utility.scale(35),
				//vOffset: this.controls.opTeamBtn.outerHeight,
				vOffset: this.height - KONtx.utility.scale(35 * 3)
			},
      events: {
        onSelect: function(event) {
				  KONtx.application.loadView('league-View');
        }
      }
    }).appendTo(this);
 
    this.controls.opTeamBtn= new KONtx.control.TextButton({
      label: "Opponent Team",
			guid: "opponent-team",
			styles: {
				height: KONtx.utility.scale(35),
				//vOffset: this.controls.myTeamBtn.outerHeight,
				vOffset: this.height - KONtx.utility.scale(35 * 2)
			},
      events: {
        onSelect: function(event) {
				  KONtx.application.loadView('oppView-View');
        }
      }
    }).appendTo(this);
		
    this.controls.videoBtn= new KONtx.control.TextButton({
      label: "Latest Video",
			guid: "video",
			styles: {
				height: KONtx.utility.scale(35),
				//vOffset: this.controls.myTeamBtn.outerHeight,
				vOffset: this.height - KONtx.utility.scale(35)
			},
      events: {
        onSelect: function(event) {
          KONtx.application.loadView('view-Player', {
              playlist: [{
                urls: [
                  /*
                  { bitrate: 50, url: "http://" + host + "/fantasy.m4v" }, 
                  { bitrate: 1000, url: "http://" + host + "/fantasy.m4v" }
                  */
                  /*
                  { bitrate: 50, url: "rtsp://rtx.cdn.yimg.com/DCA/h00toku-webgw1.mobile.vip.sp1.yahoo.com/video.3gp" }, 
                  { bitrate: 1000, url: "rtsp://rtx.cdn.yimg.com/DCA/h00toku-webgw1.mobile.vip.sp1.yahoo.com/video.3gp" }, 
                  */
                  { bitrate: 50, url: "rtsp://rtx.cdn.yimg.com/DCA/8hdivku-webgw1.mobile.vip.sp1.yahoo.com/video.3gp" }, 
                  { bitrate: 1000, url: "rtsp://rtx.cdn.yimg.com/DCA/8hdivku-webgw1.mobile.vip.sp1.yahoo.com/video.3gp" }, 
                ]
              }]
          });
        }
      }
    }).appendTo(this);
	},
	
	updateView: function() {
    var myUrl = new URL;
    myUrl.location = "http://" + host + "/trashtalk.php";
    this.teamData.blast = myUrl.fetch();
    this.controls.teamBlast.setText(this.teamData.blast);
    print(this.teamData.blast);
	}
});
